
#pragma once

#include <cstdlib>
class ShaderProgram
{
  public:
    /*
    着色器程序必须在运行时被动态编译
    */
    virtual unsigned int createShaderProgram();

    virtual void update() = 0;

    virtual ~ShaderProgram(){
      
    }

  protected:
    /**
    顶点着色器源代码
    Next we declare all the input vertex attributes in the vertex shader
    with the in keyword. Right now we only care about position data so we
    only need a single vertex attribute. GLSL has a vector datatype that
    contains 1 to 4 floats based on its postfix digit. Since each vertex has
    a 3D coordinate we create a vec3 input variable with the name aPos. We
    also specifically set the location of the input variable via layout
    (location = 0)

    使用in关键字声明 输入的顶点属性(input vertex attributes )
    因为输入的顶点有三个坐标，所以创建 vec3 并命名为 aPos
    */
    const char* vertexShaderSource;
    /**
    片段着色器源代码
    The fragment shader only requires one output variable and that is a vector
    of size 4 that defines the final color output that we should calculate
    ourselves. We can declare output values with the out keyword, that we here
    promptly named FragColor. Next we simply assign a vec4 to the color output
    as an orange color with an alpha value of 1.0 (1.0 being completely opaque).
    */
    const char* fragmentShaderSource;

    /**
    类成员变量是原始类型（如int）时，默认不会初始化，其值是未定义的（可能是内存中的随机值）。

    这是 C++ 出于性能考虑的设计：不强制初始化，避免不必要的开销。
    */
    unsigned int shaderProgram = 0;

    int compileShader(const char* shaderSource, int shaderType);
};